<?php
class HttpData{
    public static function result($type, $code, $msg, $data, $cache=0){
        global $Cache;
        if ($type == 'json') {
            header('Content-Type: application/json');
        }else if ($type == 'xml') {
            header('Content-Type: text/xml');
        }else if ($type == 'html') {
            header('Content-Type: text/html');
        }
        $result = array(
            'code' => $code,
            'msg' => $msg,
            'data' => $data,
            'time' => time()+$cache,
            'type' => $type
        );
        if($cache>0){
            // 写入文件
            $file = fopen('./cache/'.hash("sha256", json_encode($_GET)).'.cache', 'w');
            fwrite($file, json_encode($result));
            fclose($file);
        }
        return $result;
    }
}

$respone = new HttpData();